package com.leyou.trade.web;

import com.leyou.trade.entity.CartItem;
import com.leyou.trade.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/cart")
public class CartController {

    @Autowired
    private CartService cartService;
    @PostMapping
    public ResponseEntity<Void>addCart(@RequestBody CartItem cartItem){
        this.cartService.addCart(cartItem);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }
@GetMapping("/list")
    public ResponseEntity<List<CartItem>>queryCartList(){


        return ResponseEntity.ok(this.cartService.queryCartList());
    }
@PutMapping
    public ResponseEntity<Void>updateNum(
          @RequestParam("skuId")  Long skuId,
           @RequestParam("num") Integer num
    ){
        this.cartService.updateNum(skuId,num);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }
@DeleteMapping
    public ResponseEntity<Void>deleteCart(@RequestParam("skuId") Long skuId){
        this.cartService.deleteCart(skuId);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }

    public ResponseEntity<Void>addCartItemList(@RequestBody List<CartItem>itemList){
        cartService.addCartItemList(itemList);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }
}
